package com.bilifuture.statemachine.message;

import lombok.Builder;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author bilifuture
 * @description: 状态机中统一参数，封装了业务参数
 * @date 2022-02-23
 */
@Data
@Builder
public class Message {
    
    private Map<String,Object> attrs = new HashMap<>();
    
    private Object body;
    
    /**
     * 设置属性
     *
     * @param attrName  属性名称
     * @param attrValue 属性值
     */
    public void setAttr(String attrName, Object attrValue) {
        attrs.put(attrName, attrValue);
    }
    
    /**
     * 获取属性
     *
     * @param attrName attrName
     * @param clazz    clazz
     * @return {@link T}
     */
    public <T> T getAttr(String attrName, Class<T> clazz) {
        return (T) attrs.get(attrName);
    }
    
    
}
